﻿Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Microsoft.Phone.Controls
Imports System.Collections.ObjectModel
Imports IETracker.UI.Process.PhoneClassLibrary.IETrackerServiceReference
Imports IETracker.UI.Process.PhoneClassLibrary



Partial Public Class MainPage
    Inherits PhoneApplicationPage
    Private client As New IETrackerServiceClient
    Public WithEvents _transactionList As ObservableCollection(Of TransactionList)


#Region "Page Events"
    ' Constructor
    Public Sub New()
        InitializeComponent()
        ' Set the data context of the listbox control to the sample data
        'DataContext = App.ViewModel
    End Sub

    ' Load data for the ViewModel Items
    Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles Me.Loaded
        'If Not App.ViewModel.IsDataLoaded Then
        '    App.ViewModel.LoadData()
        'End If

        'AddHandler client.GetExpenseListCompleted, AddressOf client_GetExpenseListCompleted
        'client.GetExpenseListAsync("expense")

        'AddHandler client.GetIncomeListCompleted, AddressOf client_GetIncomeListCompleted
        'client.GetIncomeListAsync("income")

        'transType = "income"
        'client.GetTransactionListAsync(transType)

        '_transactionList = New ObservableCollection(Of IETrackerServiceReference.Transactions)
        'Dim xc As New List(Of IETrackerServiceReference.Transactions)
        'xc = _upc.GetTransactionList("a")
    End Sub
#End Region

#Region "Support Procedures"
    'Private Sub client_GetExpenseListCompleted(sender As Object, e As GetExpenseListCompletedEventArgs)
    '    If e.[Error] Is Nothing Then
    '        FirstListBox.ItemsSource = e.Result
    '        ' _transactionList = e.Result
    '    End If
    'End Sub


    'Private Sub client_GetIncomeListCompleted(sender As Object, e As GetIncomeListCompletedEventArgs)
    '    If e.[Error] Is Nothing Then
    '        SecondListBox.ItemsSource = e.Result
    '    End If
    'End Sub
#End Region

#Region "Control Events"
    Private Sub SecondListBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles SecondListBox.SelectionChanged
        If SecondListBox.SelectedIndex > -1 Then
            App._selectedTransaction = SecondListBox.SelectedItem
            Dim x As Uri = New Uri("/Pages/TransactionPage.xaml", UriKind.Relative)
            SecondListBox.SelectedIndex = -1
            NavigationService.Navigate(x)
        End If
    End Sub

    Private Sub FirstListBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles FirstListBox.SelectionChanged
        If FirstListBox.SelectedIndex > -1 Then
            App._selectedTransaction = FirstListBox.SelectedItem
            FirstListBox.SelectedIndex = -1
            Dim x As Uri = New Uri("/Pages/TransactionPage.xaml", UriKind.Relative)
            NavigationService.Navigate(x)

        End If
    End Sub

    Private Sub ApplicationBarIconButton_Click(sender As System.Object, e As System.EventArgs) Handles ApplicationBarIconButtonNew.Click
        App._selectedTransaction = Nothing
        Dim tranType As String = Nothing
        If pivotTransaction.SelectedIndex = 0 Then
            tranType = "expense"
        Else
            tranType = "income"
        End If

        Dim x As Uri = New Uri("/Pages/TransactionPage.xaml?type=" & tranType, UriKind.Relative)
        NavigationService.Navigate(x)
    End Sub

    Private Sub ApplicationBarIconButtonRefresh(sender As System.Object, e As System.EventArgs)

        App.ViewModel.IsDataLoaded = False
        App.ViewModel.LoadData()
    End Sub
#End Region

   

   
End Class
